<template>
  <div class="company-style">
    <!-- 导航栏 start -->
    <van-nav-bar title="企业信息" left-arrow fixed @click-left="$router.back()" />
    <!-- 导航栏 end -->

    <!-- 内容 start -->
    <van-form @submit="save">
      <div class="content-top my-info">

        <van-cell-group>
          <van-field @click="ppShowTrade = true" v-model="companyInfo.tradeIDValue" required clickable size="large" label="所属行业" placeholder="请选择" :rules="[{ required: true, message: '请选择所属行业' }]" style="font-size: 16px" />
          <van-field @click="ppShowCompanyType =true" v-model="companyInfo.companyTypeValue" required clickable size="large" label="企业性质" placeholder="请选择" :rules="[{ required: true, message: '请选择企业性质' }]" style="font-size: 16px" />
        </van-cell-group>

        <van-cell-group style="margin-top: 10px">
          <van-field @click="ppShowLocation = true" v-model="companyInfo.locationValue" required clickable size="large" label="所在地区" placeholder="请选择" :rules="[{ required: true, message: '请选择所在地区' }]" style="font-size: 16px" />
          <!-- <van-field required clickable size="large" label="所在街道" placeholder="请选择" :rules="[{ required: true, message: '请选择所在街道' }]" style="font-size: 16px" /> -->
        </van-cell-group>

        <van-cell-group style="margin-top: 10px">
          <van-field v-model="companyInfo.linkMan" required size="large" label="联系人" placeholder="请填写" :rules="[{ required: true, message: '请填写联系人' }]" style="font-size: 16px" />
          <van-field v-model="companyInfo.address" required clickable size="large" rows="1" label="联系地址" :autosize="{ maxHeight: 120, minHeight: 24 }" type="textarea" placeholder="请填写" :rules="[{ required: true, message: '请填写联系地址' }]" style="font-size: 16px" />
          <van-field v-model="companyInfo.tel" required clickable size="large" label="联系电话" placeholder="请填写" :rules="[{ required: true, message: '请填写联系电话' }]" style="font-size: 16px" />
          <van-cell size="large" center title="公开电话" style="color: #646566">
            <template #right-icon>
              <van-switch v-model="telIsShow" size="24" />
            </template>
          </van-cell>

          <van-field v-model="companyInfo.email" clickable size="large" label="电子邮件" placeholder="请填写" :rules="[{ message: '请填写电子邮件' }]" style="font-size: 16px" />
        </van-cell-group>

        <van-cell-group style="margin-top: 10px">
          <van-cell size="large" center :border="false" title="公司简介" style="color: #646566"></van-cell>
          <van-field v-model="companyInfo.companyContent" show-word-limit maxlength="800" rows="10" autosize type="textarea" placeholder="请填写公司简介内容（尊敬的人才网企业用户，您所填写的企业基本信息必须以营业执照及企业的具体经营范围为准，禁止填写与公司基本信息无关的内容，禁止填写虚假、敏感、诱导、违规违法等相关信息。如有发现我们将立即删除，严重者停止其企业账号，并保留追究其法律责任的权利。）" style="padding: 0 16px 10px; font-size: 16px" />
        </van-cell-group>

        <div style="margin: 16px">
          <van-button type="primary" block color="#07f" round style="font-size: 18px" text="保存" native-type="submit"></van-button>
        </div>

      </div>
    </van-form>
    <!-- 内容 end -->

    <!--picker-->
		<van-popup v-model="ppShowTrade" round position="bottom">
			<van-picker title="行业选择" show-toolbar :columns="bdTrade" value-key="codeValue" @confirm="confirmTrade" @cancel="ppShowTrade=false"/>
		</van-popup>

		<van-popup v-model="ppShowCompanyType" round position="bottom">
			<van-picker title="性质选择" show-toolbar :columns="bdCompanyType" value-key="codeValue" @confirm="confirmCompanyType" @cancel="ppShowCompanyType=false"/>
		</van-popup>

		<van-popup v-model="ppShowLocation" round position="bottom">
			<van-picker title="地区选择" show-toolbar :columns="bdLocation" value-key="codeValue" @confirm="confirmLocation" @cancel="ppShowLocation=false"/>
		</van-popup>
  </div>
</template>

<script>
import { NavBar, Cell, CellGroup, Field, Switch, Picker, Popup, Button, Form, Toast } from "vant";
import myJmessage from '@/util/myJmessage';
export default {
  name: "LivePlay",
  components: {
    [NavBar.name]: NavBar,
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
    [Field.name]: Field,
    [Switch.name]: Switch,
    [Picker.name]: Picker,
    [Popup.name]: Popup,
    [Button.name]: Button,
    [Form.name]: Form
  },
  // 定义属性
  data() {
    return {
      companyInfo: {},
			telIsShow:false,
			//loading
			ppShowTrade:false,
			ppShowCompanyType:false,
			ppShowLocation:false,
      //bd
      bdTrade: this.$bd.trade,
			bdCompanyType:this.$bd.companyType,
			bdLocation:this.$bd.area,
    };
  },
  mounted() {
    this.loadData();
  },
  // 方法集合
  methods: {
    loadData() {
      this.$api.get('/CompanyMine/GetCompanyInfo').then(res => {
        if (res.success) {
          this.companyInfo = res.response;
					this.telIsShow = res.response.telIsShow =='1'
        }
        else {
          this.companyInfo.companyName = res.msg;
        }
      })
    },
    save() {
			this.companyInfo.telIsShow = this.telIsShow?"1":"0";
			// console.log(this.companyInfo);
			this.$api.post('/CompanyMine/SaveCompanyInfo',this.companyInfo).then(res=>{
				Toast(res.msg);
				if(res.success){
					this.$router.back();
				}
			})
    },
    confirmTrade(item,index) {
			this.companyInfo.tradeID = item.code,
			this.companyInfo.tradeIDValue = item.codeValue
			this.ppShowTrade = false;
    },
		confirmCompanyType(item,index) {
			this.companyInfo.companyType = item.code,
			this.companyInfo.companyTypeValue = item.codeValue
			this.ppShowCompanyType = false;
    },
		confirmLocation(item,index) {
			this.companyInfo.location = item.code,
			this.companyInfo.locationValue = item.codeValue
			this.ppShowLocation = false;
    }
  },
};
</script>